package com.eastelsoft.smartiot.bssserver.controller;

import com.eastelsoft.smartiot.bssserver.dao.*;
import com.eastelsoft.smartiot.bssserver.domain.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 数据库 [] 中表 [T_CM_OrderItem——ITEM] 的Controller类.
*  
* @author: {GenerateCode}
* 创建日期: 2019/9/4
* 修 改 人: 
* 修改日期:
* 修改内容:
* 版    本: 1.0.0
*/
@SuppressWarnings("ALL")
@RestController
@RequestMapping("/api/goldsandalwood/tcmOrderItem")
public class TCmOrderItemController extends AbstractController {
    private static Logger logger = LoggerFactory.getLogger(TCmOrderItemController.class);
     @Autowired
    private TCmOrderItemMapper tCmOrderItemMapper;
    private int page;
    private int size;
    private String orderId;

    /**
     * 列表
     */
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/listTCmOrderItem", method = RequestMethod.GET)
    public PageInfo getTCmOrderItemByIdListByPage(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size,
            @RequestParam String orderId ) {
        PageHelper.startPage(page,size,"ORDER_ITEM_ID desc");
        PageInfo pageInfo = new PageInfo(tCmOrderItemMapper.selectByOrderId(orderId));
        logger.info("******PageSize="+String.valueOf(pageInfo.getPageSize()));
        return pageInfo;
    }
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/getTCmOrderItemById", method = RequestMethod.GET)
    public TCmOrderItem getTCmOrderItemById(@RequestParam String orderItemId) {
        TCmOrderItem pojo = tCmOrderItemMapper.selectByPrimaryKey(orderItemId);
        if (pojo == null) {
            return null;
        }
        return pojo;
    }
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/getTCmOrderItemById", method = RequestMethod.GET)
    public TCmOrderItem getTCmOrderItemByOpenIdIdAndOrderStatus(@RequestParam String orderItemId,@RequestParam int orderStatus ) {
        TCmOrderItem pojo = tCmOrderItemMapper.selectBycusIdAndOrderStatus(orderItemId,orderStatus);
        if (pojo == null) {
            return null;
        }
        return pojo;
    }
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/insertTCmOrderItem", method = RequestMethod.POST)
    public Boolean insert(@RequestBody TCmOrderItem param) {
        int x= tCmOrderItemMapper.insert(param);
        return x > 0;
    }
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/updateTCmOrderItem", method = RequestMethod.POST)
    public Boolean update(@RequestBody TCmOrderItem param) {
        int x= tCmOrderItemMapper.updateByPrimaryKey(param);
        return x > 0;
    }

    /**
     * 采用物理删除 delFlag
     * @param param
     * @return
     */
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/deleteTCmOrderItem", method = RequestMethod.POST)
    public Boolean delete(@RequestBody TCmOrderItem param) {
        short delflag=1;
        param.setDelFlag(delflag);
        int x= tCmOrderItemMapper.updateByPrimaryKey(param);
        return x > 0;
    }
    // TODO add method
}